<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!-- <!DOCTYPE html> -->
<html lang="en">
<head>
<meta charset="UTF-8">
<title>软件分享系统</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<script src="js/jquery-3.3.1.js"></script>
<script src="js/bootstrap.min.js"></script>
<style>
th {
	text-align: center !important;
}

.r {
	float: right;
	margin-right: 20px;
}
.tm {
    margin-left:3px;
}
.zm { margin-left: 28px;}
</style>
</head>
<body class="bg-success">

	<div class="row">
		<div class="col-md-2"></div>
		<div class="col-md-10"><h1 style="letter-spacing:5px;">欢迎来到软件分享系统</h1></div>
	</div>
	<div class="row">
		<div class="col-md-2"></div>
		<div class="col-md-8">
			<!-- 导航 -->
			<nav class="navbar navbar-default" role="navigation">
				<div class="container-fluid">
					<div class="navbar-header">
						<button type="button" class="navbar-toggle" data-toggle="collapse"
							data-target="#example-navbar-collapse">
							<span class="sr-only">切换导航</span> <span class="icon-bar"></span>
							<span class="icon-bar"></span> <span class="icon-bar"></span>
						</button>
						<a class="navbar-brand" href="#">软件分享系统</a>
					</div>
					<div class="collapse navbar-collapse" id="example-navbar-collapse">
						<ul class="nav navbar-nav">
							<li ><a href="/rjfxsys/user?method=getUsers">用户信息</a></li>
							<li class="active"><a href="/rjfxsys/software?method=getSoftwares">软件信息</a></li>
							<li ><a href="/rjfxsys/comment?method=getComments">评论信息</a></li>
						</ul>
						<ul class="nav navbar-nav navbar-right">
						<li class="dropdown"><a href="#" class="dropdown-toggle">${username}</a></li>
                        <li class="dropdown">
                            <a href="/rjfxsys/registration?method=logout" class="dropdown-toggle">
                                退出
                            </a>
                        </li>
                    </ul>
					</div>
				</div>
			</nav>

		</div>
		<div class="col-md-2"></div>
	</div>


	<div class="row">
		<div class="col-md-2"></div>
		<div class="col-md-8 text-center">


			<div class="row">
				<div class="col-md-4">
					<div class="input-group">
						<span class="input-group-addon">课程名称</span> <input type="text"
							class="form-control" id="s_sname">
					</div>
				</div>
				<div class="col-md-1">
					<button class="btn btn-default" type="button" onclick="getSoftwaress()">搜索</button>
				</div>
				<div class="col-md-2">
				</div>
				
				
				<div class="col-md-2">
				</div>
				<div class="col-md-3">
					<button type="button" class="btn btn-success r" onclick="save()" style="width:100%;">添加</button>
					<!--  data-toggle="modal" data-target="#myModal" -->
				</div>
			</div>


			<table class="table table-hover table-bordered">
				<caption></caption>
				<thead class="text-center !important;">
					<tr>
						<th>序号</th>
						<th>软件名称</th>
						<th>公司名称</th>
						<th>软件类型</th>
						<th>价格</th>
						<th>大小</th>
						<th>发布时间</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody id="softwares" class="text-center">
				  <c:forEach items="${softwares}" varStatus="i" var="data">
				   <tr>
					    <td>${data.id}</td>
						<td>${data.name}</td>
						<td>${data.company}</td>
						<td>${data.type}</td>
						<td>${data.price}</td>
						<td>${data.size}</td>
						<td>${data.createDate}</td>
						<td>
						<button type="button" class="btn btn-success btn-sm" onclick="upd(${data.id})">修改</button>
						<button type="button" class="btn btn-warning btn-sm tm" onclick="del(${data.id})">删除</button>
						</td>
					</tr>
				   </c:forEach>
				</tbody>
			</table>
			<!-- <ul class="pagination" id="fy">
				<li><a href="#">&laquo;</a></li>
				<li class="active"><a href="#">1</a></li>
				<li><a href="#">2</a></li>
				<li><a href="#">3</a></li>
				<li><a href="#">4</a></li>
				<li><a href="#">5</a></li>
				<li><a href="#">&raquo;</a></li>
			</ul> -->
		</div>
		<div class="col-md-2"></div>
	</div>


	
</body>
<script>
//列表数据
var pageI = 1;
var pageSize = 70;
// getSoftwares(1);
function getSoftwaress(pageIndex) {
	var sname = $('#s_sname').val();
	location.href = "/rjfxsys/software?method=getSoftwares&softwareName="+sname;
}
// 添加数据
function save() {
	location.href = "addSoftware.jsp"
}

// 删除 
function del(ID) {
	$.ajax({
		url : "/rjfxsys/software?method=deleteSoftware",
		data : {
			id : ID
		},
		type : "POST",
		success : function(data) {
			console.log(data);
			data = JSON.parse(data);
			if (data.msg == "ok") {
				alert("删除成功！");
				//getSoftware();
				location.href = "/rjfxsys/software?method=getSoftwares"
			} else {
				alert('删除失败！'
						+ (data.handle != 'undefind' ? data.handle : ""));
			}
		}
	})
}

// 渲染修改页面
function upd(ID) {
	<%-- var ID = '<%=session.getAttribute("softwareId")%>'; --%>
	location.href = "editSoftware.jsp?id="+ID;
}

</script>
</html>